package com.atguigu.springcloud.service.serviceImpl;


import com.atguigu.springcloud.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author yangjin
 * @Description
 * @Date 2021/7/6/23:15
 **/
@EnableBinding(Source.class)//可以理解为一个消息发送者的实例
public class IMessageProviderImpl implements IMessageProvider {

    @Resource
    private MessageChannel output;//发送消息的管道

    @Override
    public String sendMessage() {
        String serial = UUID.randomUUID().toString();
        this.output.send(MessageBuilder.withPayload(serial).build()); // 创建并发送消息
        System.out.println("***serial: "+serial);

        return serial;
    }
}